<template>
  <el-row :gutter="10" style="height: 600px">
    <el-col :span="6" style="height: 100%">
      <div style="height: 100%">
        <span><i class="el-icon-coin" style="color: rgb(103, 194, 58);"></i><b>文件列表</b></span>
        <div class="field-card" style="overflow-y: auto;height: calc(100% - 20px)">
          <el-row v-for="(item,index) in fileList" :key="index" style="padding: 2px 5px;">
            <el-button type="primary" @click="showFile(item)">{{ item }}</el-button>
          </el-row>
        </div>
      </div>
    </el-col>
    <el-col :span="18" style="height: 100%;padding: 10px">
      <pre v-html="fileContent" style="height: 100%;overflow-y: auto" v-loading="loading"></pre>
    </el-col>
  </el-row>
</template>

<script>
import {getLogFileByName, getLogFiles} from "@/api/log";
import {onMounted, reactive, toRefs} from "vue";

export default {
  name: "FileLogView",
  setup(props) {
    const state = reactive({
      fileList: [],
      fileContent: '',
      loading:false
    })
    const showFile = async (fileName) => {
      state.loading = true
      let resp = await getLogFileByName(fileName)
      state.loading = false
      state.fileContent = resp.data[0]
    }
    onMounted(async () => {
      let resp = await getLogFiles()
      state.fileList = resp.data
    })
    return {
      ...toRefs(state),
      showFile
    }
  }
}
</script>

<style scoped>

</style>
